package com.rbac.admin.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置类
 * 
 * @author rbac-admin
 * @since 2024-01-20
 */
@Configuration
public class SwaggerConfig {

    /**
     * OpenAPI 配置
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(info())
                .addSecurityItem(new SecurityRequirement().addList("Bearer Token"))
                .components(new io.swagger.v3.oas.models.Components()
                        .addSecuritySchemes("Bearer Token",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")
                                        .description("请输入 Bearer Token")
                        )
                );
    }

    /**
     * API 信息配置
     */
    private Info info() {
        return new Info()
                .title("RBAC权限管理系统接口文档")
                .description("基于Spring Boot 3 + Sa-Token的RBAC权限管理系统")
                .version("v1.0.0")
                .contact(new Contact()
                        .name("rbac-admin")
                        .email("admin@rbac.com")
                        .url("https://github.com/rbac-admin")
                )
                .license(new License()
                        .name("MIT License")
                        .url("https://opensource.org/licenses/MIT")
                );
    }
}